home *** CD-ROM | disk | FTP | other *** search
- Path: news.smartt.com!usenet
- From: kparkin@smartt.com (The REFEREE)
- Newsgroups: comp.lang.c++
- Subject: HELP !! Please !! Read Me !!!!
- Date: Tue, 26 Mar 1996 04:01:50 GMT
- Organization: Student@BCIT
- Message-ID: <4j7prk$j0h@ktk2.smartt.com>
- NNTP-Posting-Host: burn-m035.smartt.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hello there fellow C++ programmers,
-
- I am new here and I don't quite know how thing work in this group yet,
- but I was wondering if there is some nice person out there that is
- willing to help me with a small program that I am writing.
-
- Also, if there are any "hacker" who just want a small program to play
- with and make...feel free to help me out as well.
-
- I will greatly appricieate it. (Please read this whole document. I
- have added personal notes in the middle and at the very end of this
- posting )
-
- Here is the specs of the assignment :
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++
- Objectives:
-
- --> Design a procedural program using C++ iostreams, and reference
- parameters.
- --> Create a simple binary search tree.
-
- Method:
-
- Here is where you get another crack a building a binary tree and this
- time you just have to build the tree in memory. The program reads an
- arbitrary text file, parses each word from the file, and inserts the
- word into a binary search tree. After the file has been read, the
- user can print the tree in order, or search for a specific word in the
- tree. Specifically:
-
- 1) The user can specify which text file the program reads either as a
- command line parameter or in response to a prompt from the program. If
- the user specified file does not exist, then the program shall
- terminate with an appropriate error message.
- 2) The program shall parse the text file for words. A word is any
- sequence of characters separated by blanks. Each word is added to the
- binary search tree. In the case of duplicate words, a word count shall
- be incremented.
- 3) Once the file is read, the program prompts the user for a command.
- The program shall support 3 commands:
- ╖ quit - terminate the program
- ╖ print - print the search tree in order. Each word is printed, along
- with its occurrence count.
- ╖ find - find a specific word. If the word is found, it is printed
- along with its occurrence count.
-
- Here is the header file tree.h:
-
- #ifndef _TREE_H
- #define _TREE_H
-
- typedef struct _TNODE {
- char *string;
- int cnt;
- struct _TNODE * left;
- struct _TNODE * right;
- } TNODE;
-
- typedef TNODE * TNODE_PTR;
-
- //------------------------------------------
- // takes a character string and constructs
- // a correctly initialized TNODE. Returns a
- // pointer to the newly created TNODE.
- //
- TNODE_PTR tnMake(char *);
- //-------------------------------------------
- // takes a root pointer to a binary search
- // tree and recursively prints it in order.
- //
- void tnPrint(TNODE_PTR);
- //-------------------------------------------
- // prints a single TNODE, prints string and
- // the count.
- //
- void tnPrintNode(TNODE_PTR);
- //-------------------------------------------
- // searches the binary search tree for a
- // specific TNODE with a string matching the
- // character string. Returns a pointer to the
- // node if found, otherwise returns NULL.
- //
- TNODE_PTR tnFind(TNODE_PTR, char *);
- //--------------------------------------------
- // add a word to the binary search tree. If
- // the word does not already exist in the tree
- // then add a new TNODE to the tree, otherwise
- // simply increment the count of the matching
- // TNODE.
- //
- void tnAdd(TNODE_PTR&, char *);
-
- #endif
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- I also have included a bit of code called prompt.ccp and promt.h.
- Please use these codes and add to them to create this program.
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- PROMPT.CPP
-
- #include "prompt.h"
-
- char *prompt(char *msg)
- {
- static char cmdBuff[80]="";
- static char *buffPtr = cmdBuff;
- char * token;
-
- token = strtok(buffPtr, "\n\t ");
- while (token == NULL)
- {
- buffPtr = cmdBuff;
- cout << msg;
- if(!cin.getline(cmdBuff, 80))
- {
- cout << endl << "Input Error: program exit" << endl;
- exit(1);
- }
- else
- {
- token = strtok(buffPtr, "\n\t ");
- buffPtr = NULL;
- }
- }
-
- return token;
- }
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- PROMPT.H
-
- #ifndef _PROMPT_H
- #define _PROMPT_H
- #include <string.h>
- #include <iostream.h>
- #include <stdlib.h>
-
- char *prompt(char *msg);
-
- #endif
-
- +++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- If anyone out there would like to help out....please do. I am stuck
- from here on out.
-
- If you can finish this SMALL program, please send me a completed
- version with all the files, etc. Please try to send them to me via.
- E-mail or you can also post it back to the Internet.
-
- You will receive credit where it is deserved.
-
- I thank you for your time and I hope you will be able to help me out.
-
- P.S. This is not for a finicial gain. It is an assignment that I was
- given in class at school.
-
-
-
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
- It takes a big man to cry, but it takes a
- bigger man to laugh at that man. -- Jack Handy
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-
- Ken Parkin ( REFEREE on mIRC )
-
- E-mail #1 : kparkin@smartt.com
- E-mail #2 : g1140066@bcit.bc.ca
- HmPg #1 : http://www.studentaccess.com/hp/REFEREE/
- HmPg #2 : http://www.soe.bcit.bc.ca/scas/cst/year1/setg/ken/
-
- Go Flames Go !!!!!
-
-